package com.qzsoft.system.modules.permission.roleclass.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qzsoft.system.modules.permission.roleclass.dto.SysRoleClassTreeDTO;
import com.qzsoft.system.modules.permission.roleclass.entity.SysRoleClassEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 权限角色分组表(权限角色)(SysRoleGroup)表数据库访问层
 *
 * @author zt
 * @since 2020-09-22 14:24:44
 */
@Mapper
@Repository
public interface SysRoleClassDao extends BaseMapper<SysRoleClassEntity> {

    @Select("SELECT max( order_id )  orderId FROM sys_role_class c  WHERE c.pid = #{pid} and c.has_delete = '0'")
    Integer selectMaxOrderIdByPId(String pid);

    @Select("SELECT max( order_id )  orderId FROM sys_role_class c  WHERE c.pid = '0' and c.has_delete = '0'")
    Integer selectMaxOrderId();

    @Select("SELECT id,name,'dept' as pid FROM sys_role where dept_id=#{deptId} and has_default=1 and has_delete=0")
    SysRoleClassTreeDTO queryDefaultRoleBydeptId(String deptId);

    @Select("select sr.id,sr.name,'group' as pid from sys_role_group  srg inner join sys_role sr on srg.role_id=sr.id and srg.has_delete=0 and group_id=#{groupId}")
    List<SysRoleClassTreeDTO> queryDefaultRoleByGroup(String groupId);
}